<?php

    namespace addons\zpwxsys\model;



    use think\Db;

    class Sysinit extends BaseModel
    {


        protected $name = 'zpwxsys_sysinit';


        /**
         * companycount = 企业数量
         * jobcount = 职位数量
         * notecount = 简历数量
         */
        public static function getSysinfo()
        {

            self::where('id', '>', 0)->update([
                'companycount' => Db::name('zpwxsys_companyaccount')->where('status',1)->count(),
                'jobcount' => Db::name('zpwxsys_job')->where('status',1)->count(),
                'notecount' => Db::name('zpwxsys_note')->where('status',1)->count(),
                ]);
            $sysinfo = self::where('id', '>', 0)->find();

            $data['from'] = 1;
            // $sysinfo['logo'] = self::prefixImgUrl($sysinfo['logo'],$data);


            return $sysinfo;
        }

        public function updateSysView($param)
        {

            Db::startTrans();// 启动事务
            try {
                $this->allowField(true)->save($param, ['id' => $param['id']]);
                Db::commit();// 提交事务
                return ['code' => 200, 'data' => '', 'msg' => '更新成功'];

            } catch (\Exception $e) {
                Db::rollback();// 回滚事务
                return ['code' => 100, 'data' => '', 'msg' => '更新失败'];

            }

        }

    }
